
Function.prototype.get_multi_lines = function () {
    var lines = new String(this);
    lines = lines.substring(lines.indexOf("/*") + 2, lines.lastIndexOf("*/"));
    return lines;
};


//自定义字符处理函数---- 字符串替换格式化
String.prototype.format = function (kwargs) {
    //console.log(this) // this表示调用这个函数的字符串对象 String {"nihao:{name}-{age}"}
    // 正则表达式是在/ /内表示， 正则后的g表示去this里面匹配所有的字符(执行全局匹配（查找所有匹配而非在找到第一个匹配后停止）)  i表示执行对大小写不敏感的匹配  m表示执行多行匹配
    var ret = this.replace(/\{(\w+)\}/g, function (k, m) { //k表示匹配到的字符串，m表示匹配到的分组里的值，在正则中用()表示一个分组
        //console.log(k,m);  //{name} name
        return kwargs[m]  // 把匹配到的字符串用参数的值替换
    });

    return ret;  //把替换完的字符串返回
};
String.prototype.ends_with = function (endStr) {
//字符串是否以指定字符串结尾
    var d = this.length - endStr.length;
    return (d >= 0 && this.lastIndexOf(endStr) == d);
};

//根据字符获取颜色
function get_color_by_char(char) {
    var color = parseFloat('0.' + char.charCodeAt()).toString(16).substr(2, 6).toUpperCase();
    var r = color.substr(0, 2);
    var g = color.substr(2, 2);
    var b = color.substr(4, 2);
    r = parseInt(r, 16);
    g = parseInt(g, 16);
    b = parseInt(b, 16);
    r = parseInt(r / 2) - 10;
    r = Math.max(0, r);
    g = parseInt(g / 2) - 10;
    g = Math.max(0, g);
    b = parseInt(b / 2) - 10;
    b = Math.max(0, b);
    r = '00' + r.toString(16)
    g = '00' + g.toString(16)
    b = '00' + b.toString(16)
    r = r.substr(r.length - 2, r.length)
    g = g.substr(g.length - 2, g.length)
    b = b.substr(b.length - 2, b.length)
    color = r.toString(16) + g.toString(16) + b.toString(16)
    return color
}

function set_cookie(name, value, days = 365, total_station = true) { //设置cookie
    kv = name + '=' + value;

    var d = new Date();
    d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));


    var expires = 'expires=' + d.toUTCString();

    if (total_station) {

        //var domain_param = 'domain=.mspms.com;path=/';
        var domain_param = 'domain=.' + DOMAIN_NAME + ';path=/';
    } else {
        var domain_param = '';
    }

    if (days === 'temp') {
        document.cookie = [kv, domain_param].join(';');

    } else {
        document.cookie = [kv, expires, domain_param].join(';');
    }


}

function get_cookie(name) {
    //cookie的格式 key1=value1;key2=value2...
    for (e of document.cookie.split(';')) {
        var key = e.split('=')[0];
        if (!key) {
            return null;
        }
        var value = e.split('=')[1];

        key = key.trim();
        value = value.trim();

        if (key === name) {
            return value;
        }
    }
    return null;
}

function clear_cookie(name) {
    set_cookie(name, "", -1);
}


function fill_zero(text, total_count) {
    return ( '000000000000000000000000'+text).slice(-total_count);
}


